﻿Imports System.Data.SqlClient

Public Class frmSearchEmp
    Sub LoadEmp()
        Try
            Dim cmd As New SqlCommand("SELECT EmpNo,FullNameEn from StaffProfiles Where FullNameEn like N'%" & Me.txtEmpName.Text & "%' Order by EmpNo", cnn)
            Dim Reader As SqlDataReader
            Me.ListView1.Items.Clear()
            Dim FullName As String

            cnn.Open()
            Reader = cmd.ExecuteReader
            While (Reader.Read)
                FullName = (CStr(Reader.Item("EmpNo")) + " " + Reader.Item("FullNameEn"))
                With ListView1.Items.Add(Reader.Item("EmpNo"))
                    .SubItems.Add(FullName)
                End With
            End While
            cnn.Close()
        Catch ex As Exception
            MsgBox(ex.Message)
            If cnn.State = ConnectionState.Open Then
                cnn.Close()
            End If
        End Try
    End Sub


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        LoadEmp()
    End Sub

    Private Sub txtCustName_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtEmpName.KeyUp
        If e.KeyCode = Keys.Enter Then
            LoadEmp()
        End If
    End Sub

    Private Sub ListView1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.DoubleClick
        If Me.ListView1.SelectedItems.Count > 0 Then
            SelEmpID = Me.ListView1.SelectedItems(0).Text
            SelEmpName = Me.ListView1.SelectedItems(0).SubItems(1).Text
            Me.Close()
        End If
    End Sub

    Private Sub frmSearchEmp_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        SelEmpID = 0
        SelEmpName = ""
    End Sub
End Class